// pages/TradingAreaCenter/rankingList.js

const controller = require("../../../controllers/Controller").controller

Component({
  
  properties: {
    type: {
      type: String,
      value: ''
    },
    couponBagId: {
      type: String,
      value: '',
      observer: function (newVal) {
        this.accountTotalRewardPage()
      }
    },
  },
  data: {
    type: '',
    couponBagId: '',
    swiperNum: 0,
    rankList: [],
    rankLastPage: false,
    rankPageNumber: 1,
  },

  methods: {
    // 用户奖励累计金额分页信息
    accountTotalRewardPage() {
      let value = {}
      value.couponBagId = this.properties.couponBagId
      value.pageNumber = this.data.rankPageNumber
      controller.accountTotalRewardPage(value).then(res => {
        // res.data.list = [
        //   {
        //     nick: "雷燊（友米控股）",
        //     head: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTI9X140JXPuaLy2UqGEruLASIedQK0m5UFPWI6D5Qg8K0XZfZ6O7xJEJxxJn1z34lEgfOTolhTEzg/132",
        //     accountId: 512,
        //     accountPrice: 17.5,
        //     num: 35,
        //     mobile:12312312312
        //   },{
        //     nick: "LIKE妮",
        //     head: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTI9X140JXPuaLy2UqGEruLASIedQK0m5UFPWI6D5Qg8K0XZfZ6O7xJEJxxJn1z34lEgfOTolhTEzg/132",
        //     accountId: 11997,
        //     accountPrice: 4,
        //     num: 8
        //   },{
        //     nick: "大业qweqwe8",
        //     head: "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKW…AfIFDHqJJEDghHCAj6bpONQ0xt3HhdVm5SibW3XMp06ew/132",
        //     accountId: 13528,
        //     accountPrice: 3,
        //     num: 6,
        //     mobile:12312312312
        //   }
        // ]
        if (res.data.list.length > 6) {
          this.setData({
            swiperNum: 6
          })
        } else {
          this.setData({
            swiperNum: res.data.list.length
          })
        }
        // res.data.list.forEach(item => {
        //   if (item.nick) {
        //     item.nick = item.nick.slice(0, 2) + '****' + item.nick.slice(item.nick.length - 1)
        //   }
        // })

        this.setData({
          rankList: res.data.list,
          rankLastPage: res.data.lastPage
        })
      })
    },

    getRankMore(e) {
      let that = this
      let index = e.detail.current
      if (index == that.data.rankList.length - 7) {
        if (this.data.rankLastPage == false) {
          let value = {}
          value.couponBagId = this.properties.couponBagId
          value.pageNumber = this.data.rankPageNumber + 1
          this.setData({
            rankPageNumber: value.pageNumber
          })
          controller.accountTotalRewardPage(value).then(res => {
            // res.data.list.forEach(item => {
            //   if (item.nick) {
            //     item.nick = item.nick.slice(0, 2) + '****' + item.nick.slice(item.nick.length - 1)
            //   }
            // })
            let list = this.data.rankList
            let list2 = res.data.list
            let list3 = list.concat(list2)
            this.setData({
              rankList: list3,
              rankLastPage: res.data.lastPage
            })
          })
        }
      }
    },
  }

})